package com.bankcomm.util;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Matrix;

public class DensityUtil {
	/**
	 * 根据手机的分辨率从dip的单位转化为px(像素)
	 */
	public static int dip2px(Context context, float dipValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (dipValue * scale + 0.5f);
	}

	/**
	 * 根据手机的分辨率从px(像素)的单位转化为dip
	 */
	public static int px2dip(Context context, float pxValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (pxValue / scale + 0.5f);
	}
	
	/***
	 * 放大缩小函数
	 * @param src
	 * @return 
	 */
	public static Bitmap zoomFunction(Bitmap src, float destWidth, float destHeight) {
		Bitmap dest = null;
		int srcWidth = src.getWidth();
		int srcHeight = src.getHeight();
		
		if ((srcWidth != destWidth) || (srcHeight != destHeight)) {
			Matrix m = new Matrix();
			m.postScale(destWidth * 1.0f / srcWidth, destHeight * 1.0f / srcHeight);
			dest = Bitmap.createBitmap(src, 0, 0, srcWidth, srcHeight, m, true);
		} else {
			dest = src;
		}
		return dest;
	}
}
